﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JBeamLibrary;
using JBeamLibrary.Tools;
using JBeamLibrary.Types;

namespace DriveBeamEditor.Controls.BeamNG.Forms
{
    public partial class CopyResourcesForm : BeamNGForm
    {
        #region Properties

        public bool ShouldCopyResources
        {
            get { return cbCopyResources.Checked; }
        }

        public string SelectedVehicleName
        {
            get { return vehicleList.SelectedIndex >= 0 ? ((TaggedString)vehicleList.SelectedItem).Tag.ToStringOrEmpty() : null; }
        }

        #endregion

        #region CTORs

        public CopyResourcesForm()
        {
            InitializeComponent();
        }

        #endregion

        #region Events

        #region Overrides

        protected override void OnLoad(EventArgs e)
        {
            if (!DesignMode)
                RefreshVehicles();
            base.OnLoad(e);
        }

        #endregion

        #region Buttons

        private void btOk_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            if (!Modal)
                Close();
        }

        private void btReload_Click(object sender, EventArgs e)
        {
            RefreshVehicles();
        }

        #endregion

        #region Check boxes

        private void cbCopyResources_CheckedChanged(object sender, EventArgs e)
        {
            vehicleList.Enabled = cbCopyResources.Checked;
        }

        #endregion

        #endregion

        #region Methods

        /// <summary>Reloads the valid vehicles into the vehicles list</summary>
        public void RefreshVehicles()
        {
            /* Add valid vehicles to the list */
            vehicleList.Items.Clear();
            vehicleList.Items.AddRange(Vehicle.GetValidVehicles().Cast<object>().ToArray());
        }

        #endregion
    }
}
